package xian.woniuxy.w_memory;

import java.io.IOException;
import java.util.Arrays;

class MyStack {
    private String[] strs = new String[10];

    private int i;

    public void push(String s) {
        strs[i++] = s;
    }

    public String pop() {
        String str = strs[--i];
        strs[i] = null; // 防止内存泄漏
        return str;
    }

    @Override
    public String toString() {
        return Arrays.toString(strs);
    }
}

//===============================================================


public class App {
    public static void main(String[] args) throws IOException {
        MyStack stack = new MyStack();

        for (int i = 1; i <= 10; i++) {
            stack.push((char) (64 + i) + "");
        }

        System.out.println(stack.pop());
        System.out.println(stack.pop());
        System.out.println(stack.pop());

        System.out.println(stack);
    }
}
